package struct.advanced.queue;

import struct.advanced.heap.MaxHeap;
import struct.intermediate.queue.Queue;

/**
 * @author MAX
 * @version 1.0
 * @description 高级数据结构-基于堆的优先队列
 * @date 2022/1/23 09:30
 */
public class PriorityQueue<E extends Comparable<E>> implements Queue<E> {

    private MaxHeap<E> maxHeap;

    public PriorityQueue() {
        maxHeap = new MaxHeap<>();
    }

    @Override
    public void enqueue(E e) {
        maxHeap.add(e);
    }

    @Override
    public E dequeue() {
        return maxHeap.extractMax();
    }

    @Override
    public E getFront() {
        return maxHeap.findMax();
    }

    @Override
    public int size() {
        return maxHeap.size();
    }

    @Override
    public boolean isEmpty() {
        return maxHeap.isEmpty();
    }
}
